﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.system.purchaseManage
{
    public partial class addpurchase : System.Web.UI.Page
    {
        BLL.Customer bll = new BLL.Customer();
        Maticsoft.BLL.Dictionary dbll = new Maticsoft.BLL.Dictionary();
        Maticsoft.BLL.InventoryClass icbll = new Maticsoft.BLL.InventoryClass();
        Maticsoft.BLL.Inventory ibll = new Maticsoft.BLL.Inventory();
        public string myTabs,myLists;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData(hidwhere.Value);

                //获取分类价格
                //price.Value = icbll.GetModelList("cInvCCode=" + md.cInvCCode)[0].price;



                List<Maticsoft.Model.Dictionary> list = dbll.GetModelList("parentcode='PO_POCLASS'");
                //加载拼接出采购的所有类别
                foreach (var item in list)
                {
                    myTabs += "<th>" + item.name+ "</th>";

                    List<Maticsoft.Model.Inventory> ilist = ibll.GetModelList("dictionarycode='" + item.code + "' and buyvalue='1'");
                    //加载拼接出该类别下的所有产品
                    myLists += "<table class=\"myTable myLists\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
                                    "<tr>" +
                                    "<th width=\"55%\">产品名称</th>" +
                                    //"<th width=\"40%\">介绍</th>" +
                                    "<th width=\"15%\">单价</th>" +
                                    "<th width=\"15%\">数量</th>" +
                                    "<th width=\"15%\">小计</th>" +
                                    "</tr>";
                    foreach (var iitem in ilist)
                    {
                        myLists += "<tr class=\"body\">" +
                                        "<td>" + iitem.cInvName + "<input type=\"hidden\" name=\"cpmc\" value=\"" + iitem.cInvName + "" + iitem.cInvCode + "\"><input type=\"hidden\" name=\"cpfl\" value=\"" + item.name + "\"></td>" +
                                        //"<td>介绍1<input type=\"hidden\" name=\"cpjs\" value=\"介绍1\"></td>" +
                                        "<td>￥<span class=\"unit-price\">" + icbll.GetModelList("cInvCCode=" + iitem.cInvCCode)[0].price + "</span><input type=\"hidden\" name=\"unitprice\" value=\"" + icbll.GetModelList("cInvCCode=" + iitem.cInvCCode)[0].price + "\"></td>" +
                                        "<td class=\"tc\">" +
                                        "<span class=\"button minus\">&nbsp;</span>" +
                                        "<input class=\"number\" type=\"text\" data-price=\"" + icbll.GetModelList("cInvCCode=" + iitem.cInvCCode)[0].price + "\" value=\"0\" name=\"number\" >" +
                                        "<span class=\"button plus\">&nbsp;</span>" +
                                        "</td>" +
                                        "<td>￥<span class=\"sum-price\">0.00</span><input type=\"hidden\" name=\"sumprice\"></td>" +
                                    "</tr>";
                    }
                    myLists += "</table>";

                }



            }
        }

        void bindData(string where)
        {
            //Repeater1.DataSource = bll.GetList(where);
            //Repeater1.DataBind();
        }
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            bindData(hidwhere.Value);
        }

        protected void btnserach_Click(object sender, EventArgs e)
        {

            string where = " 1=1 ";
            //if (name.Value != null && !string.IsNullOrEmpty(name.Value))
            //{
            //    where += " and customername like '%" + name.Value + "%'";
            //}
            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }

        
    }
}